var Gallery={Album:{}};Gallery.Album.Dialog=Class.extend({_createdCallbacks:[],_descriptionError:null,_dialog:null,_dialogContainer:null,_saveCallbacks:[],_proxy:null,_titleError:null,_updatedCallbacks:[],_validationCallbacks:[],init:function(){this._proxy=new WCF.Action.Proxy({success:$.proxy(this._success,this)})},_cancel:function(){this._dialogContainer.wcfDialog("close")},_hideDescriptionError:function(){this._descriptionError&&(this._descriptionError.hide(),this._dialog.find('textarea[name="description"]').parents("dl").removeClass("formError"))},_hideTitleError:function(){this._titleError&&(this._titleError.hide(),this._dialog.find('input[name="title"]').parents("dl").removeClass("formError"))},_save:function(){var e,t,i,a=!1,s=this._dialog.find('input[name="title"]').val();for(t in s.length?s.length>255?(a=!0,this._showTitleError(WCF.Language.get("gallery.album.title.error.tooLong"))):this._hideTitleError():(a=!0,this._showTitleError(WCF.Language.get("wcf.global.form.error.empty"))),(e=this._dialog.find('textarea[name="description"]').val()).length>65535?(a=!0,this._showDescriptionError(WCF.Language.get("gallery.album.description.error.tooLong"))):this._hideDescriptionError(),this._validationCallbacks)this._validationCallbacks[t](this._dialogContainer)||(a=!0);if(!a){for(t in this._dialogContainer.find("button").disable(),i={accessLevel:this._dialog.find('select[name="accessLevel"] > option:selected').val()||0,description:e,title:s},this._saveCallbacks)i=this._saveCallbacks[t](i);this._dialogContainer.data("albumID")?this._proxy.setOption("data",{actionName:"update",className:"gallery\\data\\album\\AlbumAction",objectIDs:[this._dialogContainer.data("albumID")],parameters:{data:i}}):this._proxy.setOption("data",{actionName:"createAlbum",className:"gallery\\data\\album\\AlbumAction",parameters:{data:i}}),this._proxy.sendRequest()}},_showDialog:function(e,t){var i,a;null===this._dialog?(this._dialogContainer=$('
').data("__api",this).appendTo(document.body),this._dialog=$("
").appendTo(this._dialogContainer),i=$('
').appendTo(this._dialogContainer),a=$('").appendTo(i),$("").appendTo(i).click($.proxy(this._cancel,this)),a.click($.proxy(this._save,this))):this._dialogContainer.find("button").enable(),this._dialogContainer.data("albumID",t),this._dialog.html(e),require(["EventKey"],function(e){this._dialog.find('input[name="title"]')[0].addEventListener("keydown",function(t){e.Enter(t)&&this._save()}.bind(this))}.bind(this)),this._dialogContainer.wcfDialog({title:WCF.Language.get(t?"gallery.album.edit":"gallery.album.add")}),this._dialogContainer.wcfDialog("render"),this._dialog.find('input[name="title"]').focus()},_showDescriptionError:function(e){null===this._descriptionError&&(this._descriptionError=$('').hide(),this._dialog.find('textarea[name="description"]').after(this._descriptionError),this._dialog.find('textarea[name="description"]').parents("dl").addClass("formError")),this._descriptionError.show().text(e)},_showTitleError:function(e){null===this._titleError&&(this._titleError=$('').hide(),this._dialog.find('input[name="title"]').after(this._titleError),this._dialog.find('input[name="title"]').parents("dl").addClass("formError")),this._titleError.show().text(e)},_success:function(e,t,i){var a;switch(e.actionName){case"createAlbum":for(a in this._cancel(),(new WCF.System.Notification).show(),this._createdCallbacks)this._createdCallbacks[a](e.returnValues);break;case"getDialog":this._showDialog(e.returnValues.template,e.returnValues.albumID);break;case"update":for(a in this._cancel(),(new WCF.System.Notification).show(),this._updatedCallbacks)this._updatedCallbacks[a](this._dialogContainer)}},registerCallback:function(e,t){if("created"==e||"save"==e||"updated"==e||"validate"==e)if($.isFunction(t))switch(e){case"created":this._createdCallbacks.push(t);break;case"updated":this._updatedCallbacks.push(t);break;case"save":this._saveCallbacks.push(t);break;case"validate":this._validationCallbacks.push(t)}else console.debug("[Gallery.Album.Dialog] Given callback is invalid.");else console.debug('[Gallery.Album.Dialog] Unknown event "'+e+'"')},show:function(e){var t=[];e&&t.push(e),this._proxy.setOption("data",{actionName:"getDialog",className:"gallery\\data\\album\\AlbumAction",objectIDs:t}),this._proxy.sendRequest()}}),Gallery.Album.InlineEditor=WCF.InlineEditor.extend({_dialog:null,_permissions:{},_redirectURL:"",_sortImagesURL:"",_execute:function(e,t){var i,a;if(!this._validate(e,t))return!1;switch(i=$("#"+e).data("albumID"),t){case"delete":a=this._redirectURL,WCF.System.Confirmation.show(WCF.Language.get("gallery.album.delete.confirmMessage"),(function(e){"confirm"===e&&new WCF.Action.Proxy({autoSend:!0,data:{actionName:"delete",className:"gallery\\data\\album\\AlbumAction",objectIDs:[i]},success:function(e,t,i){new WCF.System.Notification(WCF.Language.get("gallery.album.delete.success")).show((function(){window.location=a}))}})}));break;case"edit":this.getDialog().show(i);break;case"sortImages":window.location=this._sortImagesURL}},_getPermission:function(e){return this._permissions[e]?this._permissions[e]:0},_getTriggerElement:function(e){return e.find(".jsAlbumInlineEditor")},_registerAlbumDialogCallbacks:function(){this._dialog.registerCallback("updated",$.proxy(this._updateAlbumData,this))},_setOptions:function(){this._options=[{label:WCF.Language.get("gallery.album.sortImages"),optionName:"sortImages"},{label:WCF.Language.get("gallery.album.delete"),optionName:"delete"},{optionName:"divider"},{label:WCF.Language.get("wcf.global.button.edit"),optionName:"edit",isQuickOption:!0}]},_updateAlbumData:function(e){var t=$(".contentHeader .contentTitle > .badge");$(".contentHeader .contentTitle").text(e.find('input[name="title"]').val()+(t?" ":"")),t&&$(".contentHeader .contentTitle").append(t),$(".contentHeader .contentHeaderDescription").text(e.find('textarea[name="description"]').val())},_validate:function(e,t){switch(t){case"delete":return!!this._getPermission("canDeleteAlbum");case"edit":return!!this._getPermission("canEditAlbum");case"sortImages":return!!this._getPermission("canSortImages")}return!1},getDialog:function(){return null===this._dialog&&(this._dialog=new Gallery.Album.Dialog,this._registerAlbumDialogCallbacks()),this._dialog},setPermission:function(e,t){this._permissions[e]=t},setPermissions:function(e){for(var t in e)this.setPermission(t,e[t])},setRedirectURL:function(e){this._redirectURL=e},setSortImagesURL:function(e){this._sortImagesURL=e}}),Gallery.Album.Share=WCF.Message.Share.Content.extend({_albumID:0,init:function(e){this._albumID=e,this._super()},_click:function(e){var t,i,a,s;e.preventDefault(),i=(t=$(e.currentTarget).prop("href")).hashCode(),void 0===this._cache[i]?(a=!1,null===this._dialog?(this._dialog=$("
").hide().appendTo(document.body),a=!0):this._dialog.empty(),s=$('

").appendTo(this._dialog),$('').attr("value",t).appendTo(s),s=$('

").appendTo(this._dialog),$('').attr("value","[album]"+this._albumID+"[/album]").appendTo(s),this._cache[i]=this._dialog.html(),a?this._dialog.wcfDialog({title:WCF.Language.get("wcf.message.share")}):this._dialog.wcfDialog("open")):this._dialog.html(this._cache[i]).wcfDialog("open"),this._enableSelection()}}),Gallery.Album.SortableImageList=Class.extend({_albumID:0,_offset:50,_proxy:null,init:function(e){this._albumID=e,this._offset=50,this._proxy=new WCF.Action.Proxy({success:$.proxy(this._success,this)}),new WCF.Sortable.List("imageList","gallery\\data\\image\\ImageAction",0,{axis:"",placeholder:"galleryImage galleryImageTiny gallerySortableImagePlaceholder",toleranceElement:""},!0,{albumID:e}),$("#loadMoreImages").click($.proxy(this._loadMoreImages,this))},_loadMoreImages:function(){this._proxy.setOption("data",{actionName:"loadSortableImages",className:"gallery\\data\\album\\AlbumAction",objectIDs:[this._albumID],parameters:{offset:this._offset}}),this._proxy.sendRequest()},_success:function(e,t,i){$("#imageList > .gallerySortableImageList").append(e.returnValues.template).sortable("refresh"),50!=e.returnValues.count&&$("#loadMoreImages").remove(),this._offset+=50}}),Gallery.Category={},Gallery.Category.MarkAllAsRead=Class.extend({_proxy:null,init:function(){this._proxy=new WCF.Action.Proxy({success:$.proxy(this._success,this)}),$(".markAllAsReadButton").click($.proxy(this._click,this))},_click:function(e){e.preventDefault(),this._proxy.setOption("data",{actionName:"markAllAsRead",className:"gallery\\data\\category\\GalleryCategoryAction"}),this._proxy.sendRequest()},_success:function(e,t,i){$(".nestedCategoryList").find(".badge.badgeUpdate").hide(),$(".galleryImageList .galleryNewImageBadge, .galleryMasonry .galleryNewImageBadge").hide(),document.querySelectorAll(".mainMenu .active .badge").forEach((e=>e.remove())),WCF.System.Event.fireEvent("com.woltlab.wcf.MainMenuMobile","updateButtonState"),(new WCF.System.Notification).show()}}),Gallery.Image={},Gallery.Image.Browser=Class.extend({_dialog:null,_isOpen:!1,_redactor:null,init:function(){this._dialog=null,this._isOpen=!1},open:function(e){if(this._isOpen)return!1;this._redactor=e,this._isOpen=!0,null===this._dialog?new WCF.Action.Proxy({autoSend:!0,data:{actionName:"getImageBrowser",className:"gallery\\data\\image\\UserImageAction",objectIDs:[WCF.User.userID]},success:$.proxy(this._initImageBrowser,this)}):(this._dialog.wcfDialog("open"),$(window).trigger("resize"))},_initImageBrowser:function(e,t,i){WCF.DOMNodeInsertedHandler.addCallback("Gallery.Image.Browser."+this._redactor.$textarea.wcfIdentify(),$.proxy(this._domNodeInserted,this)),this._dialog=$("
").hide().html(e.returnValues.template).appendTo(document.body),this._dialog.wcfDialog({onClose:$.proxy((function(){this._isOpen=!1}),this),title:WCF.Language.get("gallery.image.browser")}),new Gallery.Image.Browser.AlbumList.Loader(this),new Gallery.Image.Browser.ImageList.Loader(this),new Gallery.Image.Browser.Search.Loader(this),$(window).trigger("resize"),this._dialog.wcfDialog("render")},_insertBBCode:function(e){var t=$(e.currentTarget).data("bbcode");require(["Core"],(e=>{e.interactWithRedactor((()=>{this._redactor.buffer.set(),this._redactor.insert.text(t)}))}))},_domNodeInserted:function(){this._dialog.find(".jsGalleryImageBrowserInsertAlbum").removeClass("jsGalleryImageBrowserInsertAlbum").click($.proxy(this._insertBBCode,this));var e=this;this._dialog.find(".jsGalleryImageBrowserInsertImage").removeClass("jsGalleryImageBrowserInsertImage").each((function(t,i){var a=$(i);a.hasClass("dropdown")?WCF.Dropdown.getDropdownMenu(a.wcfIdentify()).find("li").click($.proxy(e._insertBBCode,e)):a.children("a").click($.proxy(e._insertBBCode,e))}))}}),Gallery.Image.Browser.Loader=Class.extend({_actionName:"loadImages",_cache:{},_imageBrowser:null,_list:null,_pagination:null,_pageNo:1,_pages:0,_previousPageNo:1,_proxy:null,init:function(e,t,i){this._actionName="loadImages",this._cache={},this._imageBrowser=e,this._list=$("#"+t),this._pagination=$("#"+i),this._pageNo=1,this._pages=0,this._proxy=new WCF.Action.Proxy({success:$.proxy(this._success,this)}),this._previousPageNo=1},_showPage:function(e,t){t&&t.activePage&&(t.template||(this._previousPageNo=this._pageNo),this._pageNo=t.activePage),this._cache[this._pageNo]||t&&t.template?(this._cache[this._previousPageNo]=this._list.children().detach(),t&&t.template?this._list.html(t.template):this._list.append(this._cache[this._pageNo])):this._loadItems()},_getParameters:function(){return{data:{pageNo:this._pageNo}}},_loadItems:function(){this._proxy.setOption("data",{actionName:this._actionName,className:"gallery\\data\\image\\UserImageAction",parameters:this._getParameters()}),this._proxy.sendRequest()},_success:function(e,t,i){this._showPage(null,{activePage:e.returnValues.pageNo,template:e.returnValues.template})}}),Gallery.Image.Browser.AlbumList={},Gallery.Image.Browser.AlbumList.Loader=Gallery.Image.Browser.Loader.extend({init:function(e){this._super(e,"galleryImageBrowserAlbumList","galleryImageBrowserAlbumPagination"),this._actionName="loadAlbums",this._pagination.data("pages")>1&&this._pagination.wcfPages({maxPage:this._pagination.data("pages")}).on("wcfpagesswitched",$.proxy(this._showPage,this))}}),Gallery.Image.Browser.ImageList={},Gallery.Image.Browser.ImageList.Loader=Gallery.Image.Browser.Loader.extend({init:function(e){this._super(e,"galleryImageBrowserImageList .galleryImageBrowserContainerList","galleryImageBrowserImageListPagination"),this._pagination.data("pages")>1&&this._pagination.wcfPages({maxPage:this._pagination.data("pages")}).on("wcfpagesswitched",$.proxy(this._showPage,this))}}),Gallery.Image.Browser.Search={},Gallery.Image.Browser.Search.Handler=WCF.Search.Base.extend({_searchLoader:null,init:function(e){this._super("#galleryImageBrowserImageSearchInput",null,[],!1,!0),this._delay=500,this._searchLoader=e;var t=this._searchInput.parent().removeClass("dropdown");WCF.Dropdown.removeDropdown(t.wcfIdentify())},_keyUp:function(e){switch(e.which){case $.ui.keyCode.UP:case $.ui.keyCode.DOWN:return}this._super(e)},_queryServer:function(e){this._proxy.setOption("data",{actionName:"loadImages",className:"gallery\\data\\image\\UserImageAction",parameters:this._getParameters(e)}),this._proxy.sendRequest()},_getParameters:function(e){return e.data.pageNo=1,e},_success:function(e,t,i){this._searchLoader.handleSearchResult(e)},_clearList:function(e){e&&this._searchInput.val("")}}),Gallery.Image.Browser.Search.Loader=Gallery.Image.Browser.Loader.extend({_searchString:"",init:function(e){this._super(e,"galleryImageBrowserImageSearchResultList","galleryImageBrowserImageSearchResultPagination"),this._list.hide(),new Gallery.Image.Browser.Search.Handler(this)},handleSearchResult:function(e){this._pages>1&&this._pagination.wcfPages("destroy"),this._pageNo=1,this._pages=e.returnValues.pages,this._searchString=e.returnValues.searchString,this._pagination.empty(),this._pages>1&&this._pagination.wcfPages({maxPage:this._pages}).on("wcfpagesswitched",$.proxy(this._showPage,this)),this._list.empty().hide().next("p").remove(),this._pages?(this._list.html(e.returnValues.template).show(),WCF.DOMNodeInsertedHandler.execute()):$('

'+e.returnValues.errorMessage+"

").insertAfter(this._list)},_getParameters:function(){var e=this._super();return e.data.searchString=this._searchString,e}}),Gallery.Image.Delete=WCF.Action.Delete.extend({_redirectURL:"",init:function(e,t,i){this._super(e,t),this._redirectURL=i},_success:function(e,t,i){new WCF.System.Notification(WCF.Language.get("gallery.image.delete.success")).show($.proxy((function(){window.location=this._redirectURL}),this))}}),Gallery.Image.AlbumNavigation=Class.extend({_activeImage:null,_imageList:null,_side:"left",init:function(){var e,t;this._activeImage=$(".gallerySidebarBoxImageNavigation").find("li.active"),this._imageList=$("#galleryAlbumImageNavigation"),"rtl"==WCF.Language.get("wcf.global.pageDirection")&&(this._side="right"),e=-this._activeImage.position().left+this._activeImage.outerWidth(!0),t=-this._activeImage.outerWidth(!0)*(this._imageList.children().length-3),e>0?e=0:e0;)a-=i;a!=t&&(s=$(".galleryNavigationArrowNext")).hasClass("disabled")&&(s.removeClass("disabled"),s.children(".icon").addClass("pointer")),(n={})[this._side]=a,this._imageList.animate(n,500,(function(){a!=t+3*i&&(r.addClass("disabled"),r.children(".pointer").removeClass("pointer"))}))}},_showNextImages:function(e){var t,i,a,s,n,r=$(e.currentTarget);if(!$(e.currentTarget).hasClass("disabled")){for(t=parseInt(this._imageList.css(this._side)),i=this._activeImage.outerWidth(!0),a=t-3*i;a<-i*(this._imageList.children().length-3);)a+=i;a!=t&&(s=$(".galleryNavigationArrowPrevious")).hasClass("disabled")&&(s.removeClass("disabled"),s.children(".icon").addClass("pointer")),(n={})[this._side]=a,this._imageList.animate(n,500,(function(){a!=t-3*i&&(r.addClass("disabled"),r.children(".pointer").removeClass("pointer"))}))}}}),Gallery.Image.InlineEditor=WCF.InlineEditor.extend({_environment:"list",_permissions:{},_redirectURL:"",_updateHandler:null,setRedirectURL:function(e,t){this._redirectURL=e,this._environment=t||"list"},setUpdateHandler:function(e){this._updateHandler=e},_setOptions:function(){this._options=[{label:WCF.Language.get("gallery.image.enable"),optionName:"enable"},{label:WCF.Language.get("gallery.image.disable"),optionName:"disable"},{label:WCF.Language.get("gallery.image.trash"),optionName:"trash"},{label:WCF.Language.get("gallery.image.restore"),optionName:"restore"},{label:WCF.Language.get("gallery.image.delete"),optionName:"delete"},{optionName:"divider"},{label:WCF.Language.get("wcf.global.button.edit"),optionName:"edit",isQuickOption:!0}]},_show:function(e){var t,i,a=$(e.currentTarget).data("elementID"),s=null;for(i in this._dropdowns[a]||(s=this._getTriggerElement(this._elements[a]).addClass("dropdownToggle").parent().addClass("dropdown").end(),this._dropdowns[a]=$('